import requests
from retrying import retry

myHeader = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36'
}

url = 'https://passport.17k.com/login/index.html'

data = {
    'user': '17628119492',
    'pass': '150524xyz'
}


@retry(stop_max_attempt_number=3)       # 设置重连次数
def retry_reg():
    global myHeader
    global url
    global data

    session = requests.session()
    resp = session.post(url, headers=myHeader, params=data, timeout=3)
    '''
    ssl认证报错时可以通过verify=False取消ssl认证，不认证报错时就不能加，设置超市时间（秒），设置重请求次数
    '''

    assert resp.status_code == 200 or resp.status_code == 206       # 应答码不是200或206也报错
    resp.encoding = 'utf-8'

    return resp


try:
    get_resp = retry_reg()
    with open('17k.html', 'w') as file:
        file.write(get_resp.text)
except Exception as e:
    print(e)
